﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
#include "AVLTree.h"


void test1()
{
	vector<int> v;
	srand(time(0));
	clock_t time1 = clock();
	double t1 = time1 * 1.0 / CLOCKS_PER_SEC;
	for (int i = 0; i < 20; i++)
	{
		v.push_back(rand());
	}
	for (const auto& e : v)
	{
		cout << e << ' ';
	}
	clock_t time2 = clock();
	double t2 = time2 * 1.0 / CLOCKS_PER_SEC;

	cout << endl;
	cout << time2 - time1 << endl;
	cout << CLOCKS_PER_SEC << endl;
	cout << t2 - t1 << endl;
}
void TestAVLTree1()
{
	AVLTree<int, int> t;
	 //常规的测试用例
	int a[] = { 16, 3, 7, 11, 9, 26, 18,14,15 };
	// 特殊的带有双旋场景的测试用例
	//int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	for (auto e : a)
	{
		t.Insert({ e, e });
	} 

	t.InOrder();
}

void TestAVLTree2()
{
	const int N = 400000;
	vector<int> v;
	v.reserve(N);
	//srand(time(0));
	for (size_t i = 0; i < N; i++)
	{
		v.push_back(rand() + i);
	}
	AVLTree<int, int> t;
	clock_t t1 = clock();
	for (auto e : v)
	{
		t.Insert(make_pair(e, e));
	}
	clock_t t2 = clock();
	for (auto e : v)
	{
		t.find(e);
	}
	clock_t t3 = clock();
	for (int i = 0; i < N; i++)
	{
		t.find(rand() + i);
	}
	clock_t t4 = clock();
	cout << "是否是AVL树：" << t.IsBalanceTree() << endl;
	cout << "树的高度为：" << t.TreeHeight() << endl;
	cout << "树的结点个数为：" << t.size() << endl;
	cout << "插入100000个数所需时间为：" << t2 - t1 << endl;
	cout << "查找AVL树中的所有数据所需时间为：" << t3 - t2 << endl;
	cout << "查找同样数目的随机数所需时间为：" << t4 - t3 << endl;
}

void mytest()
{
	//srand(time(0));
	for (int i = 0; i < 20; i++)
	{
		cout << rand() << ' ';
	}
}
int main()
{
	//TestAVLTree1();
	/*TestAVLTree2();*/
	return 0;
}  